package com.example.shaoying.yuejian.fragment.mainFragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.TeaAdapter;
import com.example.shaoying.yuejian.javabean.TeaList;
import com.example.shaoying.yuejian.model.ActivityModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;


public class TeacherFragment extends Fragment {
    private List<TeaList> list;
    private Context context;
    private TeaAdapter adapter;
    private View view;
    private RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.teacher, container, false);
        init();
        event();
        return view;
    }

    public void init() {
        recyclerView = (RecyclerView) view.findViewById(R.id.L_teacher);
        context = getActivity();

    }

    public void event() {

        ActivityModel model=new ActivityModel() ;
        Call<List<TeaList>> call = model.getTeaList(1);
        call.enqueue(new Callback<List<TeaList>>() {
            @Override
            public void onResponse(Call<List<TeaList>> call, Response<List<TeaList>> response) {
                list = response.body();
                adapter = new TeaAdapter(context, list);
                LinearLayoutManager manager = new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<List<TeaList>> call, Throwable t) {

            }
        });
    }
}